trigger takila_opp_product on OpportunityLineItem (before insert , before update) {
    Set<Id> pbeIds = new Set<Id>();
    Set<Id> oppId = new Set<Id>();
    Map<Id , Opportunity> OppToOppLineItemMap = new Map<id ,Opportunity>();
    Map<Id, PricebookEntry> pbeMap = new Map<Id, PricebookEntry>();
    Map<Id, Id> oppLIToOppMap = new Map<Id, Id>();
    List<Opportunity> opp1List = new List<Opportunity>();
    set<Id> opp1set = new set<Id>();
    
    for (OpportunityLineItem oli : Trigger.new){ 
        pbeIds.add(oli.pricebookentryid);
        if(!(oppId.contains(oli.OpportunityId)) ){
        	oppId.add(oli.OpportunityId);
        	System.debug('***********oppId'+oppId);
        }	
    }
    
    List<Opportunity> oppList = new List<Opportunity>([Select o.tc_curruncy__c, o.Pricebook2Id, o.Id From Opportunity o where id IN:oppId ]);
    for(Opportunity opp : oppList){
        OppToOppLineItemMap.put(opp.Pricebook2Id , opp);
        System.debug('***********opp.Pricebook2Id'+opp.Pricebook2Id);
    }
    
    Map<Id, PricebookEntry> entries = new Map<Id, PricebookEntry>(
            [select UnitPrice , Pricebook2Id from pricebookentry 
            where id in :pbeIds]);   
    
            
    
    for (OpportunityLineItem oli :trigger.new){
        if(pricebookentry.unitprice <> null ){
            if(oli.HasRevenueSchedule && oli.TotalPrice <> null){
                oli.tc_curruncy__c = oli.TotalPrice;
                //System.debug('***********oli.pricebookEntryId'+oli.pricebookEntryId+entries.get(oli.pricebookEntryId).Pricebook2Id);
            }
            else{
                    oli.tc_curruncy__c = entries.get(oli.pricebookEntryId).UnitPrice;
                    oli.TotalPrice     = oli.tc_curruncy__c ;
            }   
                    
            if(OppToOppLineItemMap.containsKey(entries.get(oli.pricebookEntryId).Pricebook2Id)){
                
                    OppToOppLineItemMap.get(entries.get(oli.pricebookEntryId).Pricebook2Id).tc_curruncy__c = oli.TotalPrice;
                    if(opp1set.add((OppToOppLineItemMap.get(entries.get(oli.pricebookEntryId).Pricebook2Id)).Id)){
                    	opp1List.add(OppToOppLineItemMap.get(entries.get(oli.pricebookEntryId).Pricebook2Id));
                    	System.debug('***********hahahaahaha'+OppToOppLineItemMap.get(entries.get(oli.pricebookEntryId).Pricebook2Id));	
                    }
            }  
        }
    }
    update opp1List;
}